#include "LidarDataManagerImpl.h"

#include <regex>
#include <sstream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <unordered_set>
#include <filesystem>

#pragma region Init
LidarDataManagerImpl::LidarDataManagerImpl()
{
}

void LidarDataManagerImpl::UseOptions(std::vector<LidarConfigurationOptions *> options)
{
    use_multi = true;

    if (_lidarMultiDriver != nullptr)
    {
        _lidarMultiDriver->stop();
        delete _lidarMultiDriver;
    }
    _lidarMultiDriver = new LidarMultiDriverX(options.size(), options);
}

bool LidarDataManagerImpl::start()
{
    if (use_multi)
    {
        if (_lidarMultiDriver != nullptr)
        {
            _lidarMultiDriver->start();
            return true;
        }
    }
    return false;
}

bool LidarDataManagerImpl::stop()
{
    if (use_multi)
    {
        if (_lidarMultiDriver != nullptr)
        {
            _lidarMultiDriver->stop();
            return true;
        }
    }

    return true;
}

bool LidarDataManagerImpl::dispose()
{
    if (use_multi)
    {
        if (_lidarMultiDriver != nullptr)
        {
            _lidarMultiDriver->stop();
            delete _lidarMultiDriver;
            _lidarMultiDriver = nullptr;
        }
    }

    return true;
}
#pragma endregion

#pragma region Callback
bool LidarDataManagerImpl::addPointCloudMsgCallback(PointCloudDataCallback callback)
{
    if (use_multi)
    {
        if (_lidarMultiDriver != nullptr)
        {
            _lidarMultiDriver->addMultiPointCloudMsgCallback(callback);
            return true;
        }
    }
    return false;
}
#pragma endregion